<template>
  <el-Card>
    <el-form :inline="true">
      <el-form-item label="一级分类">
        <el-select
          v-model="categoryStore.c1Id"
          @change="change"
          :disabled="scene ? true : false"
        >
          <el-option
            v-for="(c1, index) in categoryStore.c1Arr"
            :key="index"
            :label="c1.name"
            :value="c1.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="二级分类">
        <!-- 表单项当中下拉菜单 -->
        <el-select
          v-model="categoryStore.c2Id"
          @change="changepro"
          :disabled="scene ? true : false"
        >
          <el-option
            v-for="(c2, index) in categoryStore.c2Arr"
            :label="c2.name"
            :value="c2.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="三级分类">
        <!-- 表单项当中下拉菜单 -->
        <el-select
          v-model="categoryStore.c3Id"
          :disabled="scene ? true : false"
        >
          <el-option
            v-for="(c3, index) in categoryStore.c3Arr"
            :key="index"
            :label="c3.name"
            :value="c3.id"
          ></el-option>
        </el-select>
      </el-form-item>
    </el-form>
  </el-Card>
</template>

<script lang="ts" setup>
import { onMounted, onUnmounted } from "vue";
import useCategoryStore from "@/stores/category";
const categoryStore = useCategoryStore();
defineProps(["scene"]);
onMounted(() => {
  categoryStore.getC1();
});
onUnmounted(() => {
  categoryStore.$reset();
});

//显示二级菜单数据的change事件
const change = () => {
  categoryStore.c2Id = "";
  categoryStore.c3Arr = [];
  categoryStore.c3Id = "";
  categoryStore.getC2();
};
const changepro = () => {
  categoryStore.c3Id = "";
  categoryStore.getC3();
};
</script>

<style lang="less" scoped></style>
